const {
  addService,
  addReplayService,
  getListService,
} = require("../service/talk.service");
const { v1 } = require("uuid");

class TalkController {
  async addControl(ctx, next) {
    const { userId, groupId, content, imgUrl, link, istop, replyId, forumId } =
      ctx.request.body;
      console.log(istop,"istop")
    const requestObj = {};
    if (userId) {
      requestObj.userId = userId;
    }
    if (groupId) {
      requestObj.groupId = groupId;
    }
    if (content) {
      requestObj.content = content;
    }
    if (imgUrl) {
      requestObj.imgUrl = imgUrl;
    }
    if (link) {
      requestObj.link = link;
    }
    if (istop == 1) {
      requestObj.istop = istop;
      requestObj.forumId = "forum" + v1();
    }else {
      requestObj.istop = 0;
    }
    if (replyId) {
      requestObj.replyId = replyId;
    }
    if (forumId) {
      requestObj.forumId = forumId;
    }
    if (istop === 0) {
      requestObj.istop = 0;
    }
    const res = await addService(requestObj);
    ctx.body = {
      code:200,
      message:"添加成功",
      data:null,
    }
  }

  addReplayControl(ctx, next) {}
  async getListControl(ctx, next) {
    const requestObj = ctx.request.body;
    if (!requestObj) {
      const res = await getListService();
      console.log("---talk-control", res);
      ctx.body = {
        code: 200,
        message: "查询成功",
        data: res,
      };
    }


    if (requestObj) {
      const res = await getListService(requestObj);
      console.log("---talk-control", res.length);
      ctx.body = {
        code: 200,
        message: "查询成功",
        data: res,
      };
    }
  }
}

module.exports = new TalkController();
